import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'

//elemet-plus按需导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import * as path from "path";

let mode = process.env.NODE_ENV


// https://vitejs.dev/config/

export default defineConfig({

    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src/')
        }
    },
    dev: {
        proxy: {
            '/api': {
                target: loadEnv(mode, process.cwd()).VITE_BASE_URL,
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            },
        },

    },
    // server: {
    //     port: 8099,
    //     proxy: {
    //         '/api': {
    //             target:loadEnv(mode, process.cwd()).VITE_BASE_URL,
    //             changeOrigin: true,
    //             rewrite: (path) => path.replace(/^\/api/, '')
    //         },
    //     },
    //
    // },

    plugins: [
        vue(),
        // ...
        // 开启vue devtool，方便调试
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],

})
